﻿@model IQueryable<Website>
@using SusuCMS.Extensions;
@{
    var controller = ViewContext.ParentActionViewContext.RouteData.Values["controller"].ToString().ToLower();
    var isHome = true;
    if (controller == "page" || controller == "pagetype")
    {
        isHome = false;
    }
    var websiteId = ((AdminControllerBase)ViewContext.Controller).CurrentWebsiteId;
}
<ul id="main-menu">
    <li @if (isHome)
        { <text>class="current"</text> }>
        @Html.ActionLink("Home".Localize(), "Index", "Home")
    </li>
    @foreach (var item in Model)
    {
        <li@if (!isHome && websiteId == item.Id)
           { <text> class="current"</text> }>@Html.ActionLink(@item.Name.Summary(15), "Index", "PageType",
                new { websiteId = item.Id },
                new { @class = (item.IsOnline ? "online" : "offline") })</li>
    }
</ul>
<p class="buttons">
</p>
<script type="text/javascript">
    $(document).ready(function () {
        var list = $('#main-menu li');
        var pageSize = 12;
        if (list.length > pageSize + 1) {
            var index = $('#main-menu li.current').index();

            var start = parseInt((index - 1) / pageSize) * pageSize + 1;
            var end = start + pageSize;
            if (end > list.length) {
                end = list.length;
            }
            list.slice(1, start).hide();
            list.slice(end).hide();

            // paging
            var prev = $('<a href="javascript://"></a>');
            var next = $('<a href="javascript://"></a>');

            function setButtons() {
                prev.removeClass('disable');
                next.removeClass('disable');
                if (start <= 1) {
                    prev.addClass('disable');
                }
                if (end == list.length) {
                    next.addClass('disable');
                }
            }

            prev.click(function () {
                if ($(this).hasClass('disable')) {
                    return;
                }
                list.show();

                end = start;
                if (start - pageSize < 1) {
                    start = 1;
                }
                else {
                    start -= pageSize;
                }

                list.slice(1, start).hide();
                list.slice(end).hide();

                setButtons();
            });

            next.click(function () {
                if ($(this).hasClass('disable')) {
                    return;
                }
                list.show();

                start = end;
                if (end + pageSize > list.length) {
                    end = list.length;
                }
                else {
                    end += pageSize;
                }

                list.slice(1, start).hide();
                list.slice(end).hide();

                setButtons();
            });

            $('#main-menu').siblings('.buttons').append(prev).append(next);
            setButtons();
        }
    });
</script>
